package routers

import (
	"beego/testApp/controllers"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)

var FilterUser = func(ctx *context.Context) {
	userName := ctx.Input.Session("username")
	if userName == nil {
		ctx.Redirect(302, "/login")
	}

}

var FilterIndex = func(ctx *context.Context) {

		ctx.Redirect(302, "/admin")

}


func init() {

	beego.InsertFilter("/admin/*",beego.BeforeRouter,FilterUser)
	
    beego.InsertFilter("/",beego.BeforeRouter,FilterIndex)
	//beego.Router("/", &controllers.IndexController{})
	beego.Router("/admin", &controllers.IndexController{})
	beego.Router("/admin/userlist", &controllers.UserListController{})
	beego.Router("/admin/deladmin", &controllers.DelAdminController{})
	beego.Router("/admin/adduser", &controllers.AddUserController{})
	beego.Router("/admin/addclass", &controllers.AddClassController{})
	beego.Router("/admin/classlist", &controllers.ClassListController{})
	beego.Router("/admin/addstudent", &controllers.AddStudentController{})
	beego.Router("/admin/stulistbycid", &controllers.GetStuListByCidController{})
	beego.Router("/admin/addexam", &controllers.AddExamController{})
	beego.Router("/admin/addmenu", &controllers.AddMenuController{})
	beego.Router("/admin/menulist", &controllers.MenuListController{})
	beego.Router("/admin/menudelete", &controllers.DelMenuController{})

	beego.Router("/admin/examlistbycid", &controllers.GetExamByCidController{})
	beego.Router("/admin/addexamtpl", &controllers.ExamTplController{},"get:AddExamTpl")

	

	beego.Router("/login", &controllers.LoginController{})
	beego.Router("/logout", &controllers.LogoutController{})
	
}
